/**
 * 
 */
package com.locationhistory.utils;

import android.util.Log;

/**
 * The common logging mechanism for the whole application.
 * 
 * @author thuanlv1
 */
public class Logger {
    private static final String TAG = "DirecTV";
    private static final String DEFAULT_STRING_NULL = "null";

    /**
     * @param message
     */
    public static void debug(String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}

	Log.d(TAG, message);
    }
    
    /**
     * Debug with params input
     * 
     * @param tagName
     * @param message
     */
    public static void debug(String tagName, String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}

	if (CommonUtils.isBlank(tagName)) {
	    tagName = TAG;
	}

	Log.d(tagName, message);
    }

    /**
     * Debug with params input
     * 
     * @param className
     * @param message
     */
    @SuppressWarnings("unchecked")
    public static void debug(Class className, String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}
	if (className != null) {
	    message = className.getName() + ":" + message;
	}

	Log.d(TAG, message);
    }

    /**
     * Info debug
     * 
     * @param message
     */
    public static void info(String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}

	Log.i(TAG, message);
    }

    /**
     * Warning debug.
     * 
     * @param message
     */
    public static void warn(String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}
	Log.w(TAG, message);
    }

    /**
     * Warning debug.
     * 
     * @param tagName
     * @param message
     */
    public static void warn(String tagName, String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}

	if (CommonUtils.isBlank(tagName)) {
	    tagName = TAG;
	}

	Log.w(tagName, message);
    }

    /**
     * Error debug.
     * 
     * @param message
     */
    public static void error(String message) {
	if (message == null) {
	    // println does not handle null message while logging.
	    message = DEFAULT_STRING_NULL;
	}

	Log.e(TAG, message);
    }

    /**
     * Error debug.
     * 
     * @param ex
     *            Throwable
     */
    public static void error(Throwable ex) {
	if (ex != null) {
	    String message = Log.getStackTraceString(ex);
	    if (message != null) {
		Log.e(TAG, message);
	    }

	    ex.printStackTrace();
	}
    }
}
